<script setup>
    import {ref} from 'vue'
    import {userPasswordUpdateService} from '@/api/admin.js'
    import useUserInfoStore from '@/stores/userInfo.js'
    import {useTokenStore} from '@/stores/token.js'
    import { ElMessage } from 'element-plus';
    import {useRouter} from 'vue-router'
    const userInfoStore = useUserInfoStore();
    const tokenStore = useTokenStore();
    const router = useRouter();

    const changePasswordData = ref({
        id: userInfoStore.info.id,
        oldPassword: '',
        newPassword: '',
        repeatPassword: ''
    })

    const updatePassword = async () =>{
        let result = await userPasswordUpdateService(changePasswordData.value)
        ElMessage.success(result.msg? result.msg : '修改成功');
        tokenStore.removeToken();
        router.push('/login')

    }
</script>

<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>修改密码</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="changePasswordData" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="旧密码">
                        <el-input v-model="changePasswordData.oldPassword" type="password"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码">
                        <el-input v-model="changePasswordData.newPassword" type="password"></el-input>
                    </el-form-item>
                    <el-form-item label="重复密码">
                        <el-input v-model="changePasswordData.repeatPassword" type="password"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="updatePassword">提交修改</el-button>
                    </el-form-item>
                </el-form>

            </el-col>
        </el-row>
    </el-card>
</template>

<style scoped>

</style>

